package mgo

import (
	"go.mongodb.org/mongo-driver/bson"
)

// MapToBson map 转 bson.M
func MapToBson(m map[string]interface{}) bson.M {
	bm := make(bson.M)
	for k, v := range m {
		bm[k] = v
	}
	return bm
}

// BsonToMap bson.M 转 map
func BsonToMap(bm bson.M) map[string]interface{} {
	m := make(map[string]interface{}, len(bm))
	for k, v := range bm {
		m[k] = v
	}
	return m
}

// BsonD 结构转 bson.D
type BsonD struct {
	Key   string
	Value interface{}
}

func ToBsonD(bd []*BsonD) bson.D {
	var d bson.D
	for _, v := range bd {
		d = append(d, bson.E{v.Key, v.Value})
	}
	return d
}
